<%@ page import="com.lagou.edu.pojo.Resume" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="res.html" %>
<!doctype html>
<html>
<head>
    <title>列表</title>
    <style>
        .list-wrapper {
            width: 800px;
            margin: 200px auto;
        }

        .list-wrapper .list-button {
            text-align: right;
        }

        .list-wrapper th {
            width: 20%;
        }
    </style>
</head>
<body onload="onload(${isOnloaded})">
<form id="listForm">
    <input id="actionType" type="hidden" name="actionType" value="" />
    <input id="methodType" type="hidden" name="_method" value="" />
</form>
<div class="list-wrapper">
    <div class="list-button">
            <button id="addButton" type="button" class="btn btn-secondary"  onclick="add()">新增</button>
    </div>
    <br>
<table class="table">
    <thead class="thead-dark">
        <tr>
            <th scope="col">id</th>
            <th scope="col">地址</th>
            <th scope="col">姓名</th>
            <th scope="col">电话</th>
            <th scope="col">操作</th>
        </tr>
    </thead>
    <tbody>
    <% if (request != null) {
        List<Resume> resumes = (List<Resume>) request.getAttribute("resumes");
        if (resumes != null) {
        for (Resume resume : resumes) { %>
    <tr>
        <th scope="row"><%=resume.getId()%></th>
        <td><%=resume.getAddress()%></td>
        <td><%=resume.getName()%></td>
        <td><%=resume.getPhone()%></td>
        <td>
            <button id="editButton" type="button" class="btn btn-secondary" onclick="edit(<%=resume.getId()%>)">编辑</button>
            <button id="removeButton" class="btn btn-secondary" onclick="remove(<%=resume.getId()%>)">删除</button>
        </td>
    </tr>
    <% }}} %>
    </tbody>
</table>
</div>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.slim.min.js"
        integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
        crossorigin="anonymous"></script>
<script>
    var listForm = document.getElementById("listForm");
    var methodType = document.getElementById("methodType");
    var actionType = document.getElementById("actionType");

    function onload(isOnloaded) {
        if (!isOnloaded) {
            methodType.value = "get";
            listForm.setAttribute("action", "/sss/resumes/");
            listForm.setAttribute("method", "get");
            listForm.submit();
        }
    }

    function add() {
        methodType.value = "post";
        actionType.value = "";
        listForm.setAttribute("action", "/sss/resumes/");
        listForm.setAttribute("method", "post");
        listForm.submit();
    };

    function edit(id) {
        methodType.value = "put";
        actionType.value = "";
        listForm.setAttribute("action", "/sss/resumes/" + id);
        listForm.setAttribute("method", "post");
        listForm.submit();
    };

    function remove(id) {
        methodType.value = "delete";
        listForm.setAttribute("action", "/sss/resumes/" + id);
        listForm.setAttribute("method", "post");
        listForm.submit();
    };

</script>
</body>
</html>
